pin=0
gpio.mode(pin,gpio.OUTPUT)
gpio.write(pin,gpio.HIGH)

dht11_data_pin = 5

s = softuart.setup(9600,2,3)
s:on("data","$",function (data)    
    cmd = string.sub(data, 1, #data -1)
    print(cmd) 

    if cmd == "on" then
        gpio.write(pin,gpio.LOW)
        s:write("ok")
    elseif cmd == "off" then
        gpio.write(pin,gpio.HIGH)
        s:write("ok")
    elseif cmd == "dht11" then
        status,temp, humi = dht.read11(dht11_data_pin)
        if status == dht.OK then
         s:write(string.format("temp: %d, humi: %d",temp ,humi))
         else
            s:write("fail")
        end
    end
end) 
